Most of diffusion layers are linear transformations on the vector space GF(2 m) n for SPN structures, which correspond to n-rank matrices under certain bases. The diffusion layers in which branch numbers B equals n+1 are optimal, iff their corresponding matrices have no singular square submatrices. An algorithm was proposed to construct optimal linear layers. In order to validate the optimization of diffusion layers, an algorithm was provided. As an example, a optimal linear mapping over GF(2 8) 8 and its optimization-validation were presented.